#pragma once

#include <NxStream.h>


extern const uint PHYSICS_VISUALIZATION_PARAMS[];
extern const uint PHYSICS_VISUALIZATION_PARAM_COUNT;
extern const char * const PHYSICS_VISUALIZATION_PARAM_NAMES[];


inline common::VEC3 NxToMy(const NxVec3 &v) { return common::VEC3(v.x, v.y, v.z); }
inline common::QUATERNION NxToMy(const NxQuat &v) { return common::QUATERNION(v.x, v.y, v.z, v.w); }
inline NxVec3 MyToNx(const common::VEC3 &v) { return NxVec3(v.x, v.y, v.z); }
inline NxQuat MyToNx(const common::QUATERNION &v) { return NxQuat(NxVec3(v.x, v.y, v.z), v.w); }


class NxToLogOutputStream : public NxUserOutputStream
{
public:
	virtual void reportError(NxErrorCode code, const char *message, const char *file, int line);
	virtual NxAssertResponse reportAssertViolation(const char *message, const char *file, int line);
	virtual void print(const char *message);
};

extern NxToLogOutputStream g_NxLogger;


class NxToMyStream : public NxStream
{
public:
	NxToMyStream(common::Stream &stream) : m_Stream(stream) { }
	virtual ~NxToMyStream() { }
	virtual NxU8 readByte()     const { uint1  v; m_Stream.ReadEx(&v); return v; }
	virtual NxU16 readWord()    const { uint2  v; m_Stream.ReadEx(&v); return v; }
	virtual NxU32 readDword()   const { uint4  v; m_Stream.ReadEx(&v); return v; }
	virtual float readFloat()   const { float  v; m_Stream.ReadEx(&v); return v; }
	virtual double readDouble() const { double v; m_Stream.ReadEx(&v); return v; }
	virtual void readBuffer(void* buffer, NxU32 size) const { m_Stream.MustRead(buffer, size); }
	virtual NxStream& storeByte(NxU8 b)    { m_Stream.WriteEx(b); return *this; }
	virtual NxStream& storeWord(NxU16 w)   { m_Stream.WriteEx(w); return *this; }
	virtual NxStream& storeDword(NxU32 d)  { m_Stream.WriteEx(d); return *this; }
	virtual NxStream& storeFloat(NxReal f) { m_Stream.WriteEx(f); return *this; }
	virtual NxStream& storeDouble(NxF64 f) { m_Stream.WriteEx(f); return *this; }
	virtual NxStream& storeBuffer(const void* buffer, NxU32 size) { m_Stream.Write(buffer, size); return *this; }

private:
	common::Stream &m_Stream;
};

